package com.guang.blockqueue;

import com.guang.readandwritelock.ReadWriteLockDemoOne;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

/**
 * @author lg
 * @Description
 * @date 2022/10/31 11:06
 */
public class LinkedBlockingQueueTestOne {
    private final static Logger logger = LoggerFactory.getLogger(LinkedBlockingQueueTestOne.class);
    /**
     * 有界队列！但是实际上默认的是很大的一个值，理论上是达不到的
     */
    static BlockingQueue<String> blockingQueue  = new LinkedBlockingDeque<>();

    public static void main(String[] args) throws InterruptedException {

        Thread t1 = new Thread(() -> {
            try {
                logger.info("t1线程放入元素");
                blockingQueue.put("hello");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t1");

        t1.start();
        TimeUnit.MILLISECONDS.sleep(10);

        Thread t2 = new Thread(() -> {
            try {
                String takeResult = blockingQueue.take();
                logger.info("t2线程获取得到的元素值是：{}",takeResult);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t2");
        t2.start();
    }
}
